﻿package mortal.game.view.mainUI.shortcutbar.exSkill
{
    import com.gengine.global.*;
    import com.mui.events.*;
    import com.mui.utils.*;
    import mortal.common.*;
    import mortal.common.shortcutsKey.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.item.*;
    import mortal.game.view.mainUI.shortcutbar.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;

    public class ExSkillShortcutBar extends ShortcutBarBase
    {
        private var _items:Array;
        private var _cellWidth:int;
        private var _cellHeight:int;
        private var _cellNum:int;
        public static var eventMoveIn:Boolean;
        public static var itemIsDropable:Boolean;
        public static var beidongSkillFilter:Boolean;

        public function ExSkillShortcutBar()
        {
            return;
        }// end function

        private function moveInHandler(event:DragEvent) : void
        {
            var _loc_3:SkillInfo = null;
            var _loc_4:CDItem = null;
            var _loc_2:* = event.dragItem as CDItem;
            if (_loc_2.dragSource is SkillInfo)
            {
                _loc_3 = Cache.instance.skill.getExtSkillBySkillId(SkillInfo(_loc_2.dragSource).skillId);
                if (_loc_3 != null)
                {
                    _loc_4 = event.dropItem as CDItem;
                    Dispatcher.dispatchEvent(new DataEvent(EventName.ExShortcutBarMoveIn, {from:_loc_2, to:_loc_4}));
                }
            }
            return;
        }// end function

        public function setParams(param1:int, param2:int, param3:int) : void
        {
            var _loc_5:ShortcutBarItem = null;
            this._cellNum = param1;
            this._cellWidth = param2;
            this._cellHeight = param3;
            DisplayUtil.delNotUse(this._items, 0);
            this._items = [];
            var _loc_4:int = 1;
            while (_loc_4 <= this._cellNum)
            {
                
                _loc_5 = UICompomentPool.getUICompoment(ShortcutBarItem, _loc_4) as ShortcutBarItem;
                _loc_5.pos = _loc_4;
                _loc_5.isShowLeftTimeEffect = true;
                _loc_5.isShowFreezingEffect = true;
                _loc_5.setSize(this._cellWidth, this._cellHeight);
                _loc_5.isDragAble = false;
                _loc_5.isDropAble = itemIsDropable;
                _loc_5.isThrowAble = false;
                _loc_5.setLabelTxt(_loc_4.toString());
                _loc_5.x = _loc_4 * 43;
                _loc_5.bgName = ImagesConst.shortcutItemBg;
                this.addChild(_loc_5);
                this._items[_loc_4] = _loc_5;
                _loc_4++;
            }
            if (eventMoveIn)
            {
                this.configEventListener(DragEvent.Event_Move_In, this.moveInHandler);
            }
            return;
        }// end function

        public function updateShortcutKey(param1:Array) : void
        {
            var _loc_2:KeyMapData = null;
            var _loc_3:ShortcutBarItem = null;
            var _loc_4:String = null;
            var _loc_5:int = 0;
            while (_loc_5 < param1.length)
            {
                
                _loc_2 = param1[_loc_5];
                if (_loc_2.key is int)
                {
                    _loc_3 = this._items[_loc_2.key];
                    if (_loc_3)
                    {
                        if (_loc_2.keyData)
                        {
                            _loc_4 = _loc_2.keyData.shortcutsName;
                        }
                        else
                        {
                            _loc_4 = "";
                        }
                        _loc_3.setLabelTxt(_loc_4);
                    }
                }
                _loc_5++;
            }
            return;
        }// end function

        public function updateShortcutSource(param1:int, param2:Object) : void
        {
            var _loc_3:* = this._items[param1];
            if (_loc_3 != null)
            {
                _loc_3.dragSource = param2;
                if (beidongSkillFilter && param2 && SkillUtil.isBeidongSkill(SkillInfo(param2).tSkill.skillId))
                {
                    _loc_3.filters = [FilterConst.colorFilter];
                }
                else
                {
                    _loc_3.filters = null;
                }
            }
            return;
        }// end function

        override public function show(param1:int = 0, param2:int = 0) : void
        {
            this.onStageResize();
            LayerManager.uiLayer.addChild(this);
            return;
        }// end function

        public function onStageResize() : void
        {
            this.x = (Global.stage.stageWidth - (this._cellNum + 2) * this._cellWidth) / 2;
            this.y = Global.stage.stageHeight - this._cellHeight - 10;
            return;
        }// end function

        override public function hide() : void
        {
            super.hide();
            DisplayUtil.removeMe(this);
            eventMoveIn = false;
            itemIsDropable = false;
            beidongSkillFilter = false;
            return;
        }// end function

        public function getDragSource(param1:int) : Object
        {
            var _loc_2:* = this._items[param1] as ShortcutBarItem;
            if (_loc_2 == null)
            {
                return null;
            }
            return _loc_2.dragSource;
        }// end function

    }
}
